/*
 * AutismValidationHandler.java
 *
 * Created on November 28, 2006, 10:48 AM
 *
 * To change this template, choose Tools | Template Manager
 * and open the template in the editor.
 */

package com.asaga.tools;

import java.io.IOException;
import javax.servlet.http.*;


/**
 *
 * @author jeremys
 */
public class AutismValidationHandler {
    private SystemClient_DBImpl scdb;
    
    /** Creates a new instance of AutismValidationHandler */
    public AutismValidationHandler() {
    }
    public AutismValidationHandler(HttpServletRequest r, HttpSession s){
    }
    
    public String HandleValidation(HttpServletRequest request, HttpSession session){
        return "login.jsp";
    }
    
    public boolean makeUserSession(HttpServletRequest r, HttpSession s){
        String username = r.getParameter("username");
        String password = r.getParameter("password");
        //User_jrs_Stub u = new User_jrs_Stub();
        scdb = new SystemClient_DBImpl();
        
        
        if(scdb.getProfile(username, password)){            
            s.setAttribute("username",username);
            s.setAttribute("password",password);
            s.setAttribute("userProfile",scdb);
            return true;
        }else{
            //s.invalidate();
            s.setAttribute("username",null);
            s.setAttribute("password",null);
            s.setAttribute("userProfile",null);
            return false;
        }
    }
    public boolean checkUserSession(HttpSession s, HttpServletResponse rs){
        if(s.getAttribute("username")==null){
            /*
            try {
                rs.sendRedirect("login.jsp");
            } catch (IOException ex) {
                ex.printStackTrace();
            }
            //s.invalidate();
             */
            s.setAttribute("username",null);
            s.setAttribute("password",null);
            s.setAttribute("userProfile",null);
            return false;
        }else{
            return true;
        }
    }
    
    public SystemClient_DBImpl getUserSession(){
        return this.scdb;
    }
    
}
